<template>
    <label>
        <input
            type="radio"
            v-model="model"
            placeholder-class="input-placeholder"
            :name="name"
            :value="label"
            :disabled="isDisabled"
            ref="radio"
            role="radio"
        />
        <span>
            <slot></slot>
            <template v-if="!$slots.default">{{label}}</template>
        </span>
    </label>
</template>

<script>
    export default {
        name: 'LeRadio',
        data() {
            return {
                radioGroup: {}
            }
        },
        props: {
            label: {},
            value: {},
            disabled: Boolean,
            name: String
        },
        computed: {
            isDisabled() {
                return this.disabled;
            },
            isGroup() {
                let parent = this.$parent;
                while (parent) {
                if (parent.$options.componentName !== 'LeRadioGroup') {
                    parent = parent.$parent;
                } else {
                    console.log('AAAAAAA');
                    
                    // this._radioGroup = parent;
                    return true;
                }
                }
                return false;
            },
            model: {
                get() {
                    this.isGroup
                    return this.value;
                },
                set(val) {
                    this.$emit('input', val);
                    this.$refs.radio && (this.$refs.radio.checked = this.model === this.label);
                }
            }
        }
    }
</script>

<style lang="scss" scoped>

</style>